{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "c303bf18-8a43-46aa-ae6d-317d3ece13df",
   "metadata": {},
   "source": [
    "Chapter 08\n",
    "# 自定义函数中使用*args\n",
    "Book_1《编程不难》 | 鸢尾花书：从加减乘除到机器学习 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "db6454b2-105d-4318-9506-fe7c093bc35f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 利用*args\n",
    "def multiply_all(*args):\n",
    "    result = 1\n",
    "    print(args)\n",
    "    for num_idx in args:\n",
    "        result *= num_idx\n",
    "    return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "90604ff4-9009-48be-b0ed-8393b3a99d32",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1, 2, 3, 4)\n",
      "24\n"
     ]
    }
   ],
   "source": [
    "# 计算4个值的乘积\n",
    "print(multiply_all(1, 2, 3, 4))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "06e635d7-f4a5-4d77-80fd-e06e225468fd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1, 2, 3, 4, 5, 6)\n",
      "720\n"
     ]
    }
   ],
   "source": [
    "# 计算6个值的乘积\n",
    "print(multiply_all(1, 2, 3, 4, 5, 6))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
